﻿using PKTools.Database;
using PKTools.Generator;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServiceStack.Text;
using PKTools.Scheduler;

namespace PKTools.Test
{
    class Program
    {        
        static void Main(string[] args)
        {
            //var g = new MsSqlGenerator(null);
            
            Job
                job;
            using (var sql = new MsSql())
            {
                job = sql.LoadByPK<Job>(1);

                
                var
                    js = new JobSchedule { Properties = "dupa" };

                sql.BeginTransaction();
                sql.Insert(js);
                sql.Commit();

                job.JobSchedule.ID = 1;

                dynamic
                    temp;
                temp = sql.LoadDynamic("SELECT Name FROM JOB WHERE ID = 1");

                temp = sql.LoadDynamicList("SELECT Name FROM JobStep");

                var
                    steps = job.JobStepList;


                
                var
                    conn = job.JobStepList[0].Alias.Connection;

                conn = job.JobStepList[0].Alias.Connection;

                bool
                    failure = job.JobHistoryList.Any(e => e.JobStepHistoryList.Any(f => !f.IsSuccess));
            }

            using (var ss = new MsSql())
            {
                using (new Stoper("serialize"))
                    File.WriteAllText("dump.txt", job.Dump());

                using (new Stoper("serialize"))
                    File.WriteAllText("type.txt", TypeSerializer.SerializeToString<Job>(job));

                using (new Stoper("serialize"))
                    File.WriteAllText("json.txt", JsonSerializer.SerializeToString<Job>(job));

            }
        }
    }
}
